package com.c2soft.ncmxBtrade.webApp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MarshallingHttpMessageConverter;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.web.client.RestTemplate;

import com.c2soft.ncmxBtrade.command.*;

@Configuration
public class JavaConfig {

	@Bean
	public RestTemplate restTemplate() {
		RestTemplate restTemplate = new RestTemplate();
		List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();

		converters.add(new MappingJackson2HttpMessageConverter());
		converters.add(marshallingMessageConverter());
		converters.add(new StringHttpMessageConverter());
		restTemplate.setMessageConverters(converters);

		return restTemplate;
	}

	@Bean
	public MarshallingHttpMessageConverter marshallingMessageConverter() {
		return new MarshallingHttpMessageConverter(jaxb2Marshaller(),
				jaxb2Marshaller());
	}

	@Bean
	public Jaxb2Marshaller jaxb2Marshaller() {
		Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
		marshaller
				.setClassesToBeBound(new Class[] { BrokeOrderCommand.class });
		return marshaller;
	}

}
